// pagesProperty/pages/active/list/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"), common_Js = require("../../../../component/common.js")
import Dialog from '../../../../component/vant/dialog/dialog';
import Toast from '../../../../component/vant/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeList:[],
    activeTypeList:[],
    pageIndex:1,
    pageSize:10,
    loading: false,
    netWork: true,
    isLoading: true,
    netWork:false,
    hasData:false,
    active_type:0,
    currentTab:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.onHttpInit();
  },
  
  handleChange({detail}){    
    console.log('detail',detail)
    this.data.pageIndex = 1;
    this.setData({
      activeList : [],
      currentTab: detail.index
    })
    this.data.active_type = this.data.activeTypeList[detail.index].dictValue;
    this.onHttpInit();
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    var that = this;
    fetchApi.httpPost('/active/list', {
      active_type: that.data.active_type,
      pageIndex: that.data.pageIndex,
      pageSize: that.data.pageSize,
    }, function (res) {
      console.log("活动详情数据", res)
      if (res.data.code == 0) {
        var activeList = res.data.data.activeList;
        that.data.activeTypeList = res.data.data.activeTypeList;
        that.setData({
          activeTypeList: that.data.activeTypeList
        })
        if(activeList.length > 0){
          that.data.pageIndex += 1;
          for (var index in activeList) {
            that.data.activeList.splice(that.data.activeList.length, 0, activeList[index]);
          }
          that.setData({
            hasData: true,
            activeList: that.data.activeList
          })
        }else{
          that.setData({
            hasData: false,
          })
        }
      }else{
        that.setData({
          hasData: false,
        })
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.data.pageIndex = 1;
    this.setData({
      isLoading:true,
      activeList:[],
    })
    this.onHttpInit();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.onHttpInit();
  },
})